using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web.Admin;
using System;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Admin_MBF_UserCardStoreEdit : Admin, IRequiresSessionState
{
	protected HiddenField h_id;
	protected DropDownList ddl_CardCategory;
	protected RequiredFieldValidator rfv1;
	protected TextBox txtFaceValue;
	protected RequiredFieldValidator rfv2;
	protected TextBox txtDiscountRate;
	protected RequiredFieldValidator rfv4;
	protected HiddenField h_Pictrue;
	protected Image Image_Pictrue;
	protected FileUpload FileUpload_Pictrue;
	protected Button ButtonRemovefile;
	protected Literal ltr_Pictrue;
	protected Button Add;
	protected Button ButtonReturn;
	private HoWave.Data.Bll.UserCardStore bllCardStore = HoWave.Data.Bll.UserCardStore.instance;
	private HoWave.Data.Bll.UserCardCategory bllCardCategory = HoWave.Data.Bll.UserCardCategory.instance;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!this.Page.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(38))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "MBF_UserCardStoreEdit");
				base.WriteRightErrMsg();
			}
			this.ddl_CardCategory.bindTableToDropDownList(this.bllCardCategory.GetDropDownListData(""), true, false);
			int iD = Fetch.GetID("id");
			if (iD > 0)
			{
				this.ShowInfo(iD);
			}
		}
	}
	private void ShowInfo(int id)
	{
		HoWave.Data.Model.UserCardStore model = this.bllCardStore.GetModel(id);
		this.h_id.Value = model.id.ToString();
		this.ddl_CardCategory.ddlSelect(model.CardCategory);
		this.txtFaceValue.Text = model.FaceValue.ToString();
		this.txtDiscountRate.Text = model.DiscountRate.ToString();
		this.h_Pictrue.Value = model.Pictrue;
		this.Image_Pictrue.ImageUrl = "~/UpLoadFile/VIPCardPic/" + model.Pictrue;
	}
	protected void ButtonReturn_Click(object sender, EventArgs e)
	{
		base.Response.Redirect("MBF_UserCardStoreManage.aspx?MenuID=5&MenuName=卡类管理&FileName=VIP卡面值管理#pos_" + this.h_id.Value);
	}
	protected void Add_Click(object sender, EventArgs e)
	{
		string text = "";
		if (this.ddl_CardCategory.SelectedIndex == 0)
		{
			text += "请选择卡类别！\\n";
		}
		if (!PageValidate.IsDecimal(this.txtFaceValue.Text))
		{
			text += "面值格式错误！\\n";
		}
		if (!PageValidate.IsNumber(this.txtDiscountRate.Text))
		{
			text += "返还比率格式错误！\\n";
		}
		if (text != "")
		{
			MessageBox.Show(this, text);
		}
		else
		{
			string selectValue = this.ddl_CardCategory.GetSelectValue(new string[0]);
			decimal value = decimal.Parse(this.txtFaceValue.Text);
			int value2 = int.Parse(this.txtDiscountRate.Text);
			string text2 = "";
			if (this.FileUpload_Pictrue.HasFile)
			{
				UploadFile uploadFile = new UploadFile("~/UpLoadFile/VIPCardPic");
				uploadFile.Extension = ".png,.jpg,.gif";
				string text3 = uploadFile.DoUploadFile(this.FileUpload_Pictrue, true, new string[0]);
				if (text3 == "")
				{
					if (this.Image_Pictrue.ImageUrl != "")
					{
						FileIO.DelecteFile(base.Server.MapPath(this.Image_Pictrue.ImageUrl));
					}
					text2 = uploadFile.FileName;
				}
				else
				{
					this.ltr_Pictrue.Text = text3;
				}
			}
			else
			{
				text2 = this.h_Pictrue.Value;
			}
			if (text2.Trim() == "")
			{
				MessageBox.Show(this, "请选择一张图片！");
			}
			else
			{
				HoWave.Data.Model.UserCardStore userCardStore = new HoWave.Data.Model.UserCardStore();
				userCardStore.CardCategory = selectValue;
				userCardStore.FaceValue = new decimal?(value);
				userCardStore.DiscountRate = new int?(value2);
				userCardStore.Pictrue = text2;
				if (this.h_id.Value == "")
				{
					this.bllCardStore.Add(userCardStore);
				}
				else
				{
					userCardStore.id = int.Parse(this.h_id.Value);
					this.bllCardStore.Update(userCardStore);
				}
				this.Image_Pictrue.ImageUrl = "~/UpLoadFile/VIPCardPic/" + userCardStore.Pictrue;
				MessageBox.ShowAndRedirect(this, "保存成功！", "MBF_UserCardStoreManage.aspx?MenuID=5&MenuName=卡类管理&FileName=VIP卡面值管理#pos_" + userCardStore.CardCategory);
			}
		}
	}
}
